package adapter.common
{
	import datapool.Context;
	import ui.common.IUIBase;
	/**
	 * @author Administrator
	 */
	public class AdapterBase
	{
		private var _ui:IUIBase;
		
		public function AdapterBase()
		{	
		}
		
		protected function get ui():IUIBase
		{
			return _ui;
		}
		
		public function attachUI(uiObject:IUIBase):void
		{
			if(_ui)
			{
				deattachUI();
			}
			if(uiObject)
			{
				_ui = uiObject;
				_ui.attachAdapter(this);
				onUIAttach();
				refreshNotify();
			}
		}
		
		public function deattachUI():void
		{
			if(_ui)
			{
				onUIDeattach();
				_ui.deattachAdapter();
				_ui = null;
			}
		}
		
		protected function onUIAttach():void
		{	
		}
		
		protected function onUIDeattach():void
		{
		}
		
		protected function refreshNotify():void
		{
			if(_ui)
			{
				_ui.update();
			}
		}
		
		protected function get context():Context
		{
			return Context.inistance;
		}
	}
}
